package com.ruoyi.web.controller.monitor;

import com.ruoyi.system.domain.ScClaTime;
import com.ruoyi.system.domain.SysTeacherUser;
import com.ruoyi.system.domain.SysUserCid;
import com.ruoyi.system.mapper.ScClaTimeMapper;
import com.ruoyi.system.mapper.SysTeacherUserMapper;
import com.ruoyi.system.mapper.SysUserCidMapper;
import com.ruoyi.web.core.config.GeTuiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @ClassName ScheduledTask * @Description TODO
 * @Author ZQB
 * @Date 20:14 2024/3/3
 * @Version 1.0
 **/
@Component
public class ScheduledTask {


    @Autowired
    private GeTuiUtils geTuiUtils;
    @Autowired
    private ScClaTimeMapper scClaTimeMapper;
    @Autowired
    private SysTeacherUserMapper sysTeacherUserMapper;

    @Autowired
    private SysUserCidMapper sysUserCidMapper;


//    @Scheduled(cron = "0 25,55 7-23 * * ?") // 每小时的25分和55分从7点到23点执行一次
//    @Scheduled(fixedRate= 3000)
    public void ScheduledMethod() {

     // 获取当前时间戳
        long currentTimeMillis = System.currentTimeMillis();

        // 将时间戳转换为Date对象
        Date date = new Date(currentTimeMillis);

        // 创建SimpleDateFormat对象，指定日期时间格式为'yyyy-MM-dd HH:mm:ss'
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 格式化日期对象为字符串
        String dateTimeString = sdf.format(date);
        List<ScClaTime> scClaTimes = scClaTimeMapper.selectScClaTimeListByDate(dateTimeString);
        for (ScClaTime scClaTime:
        scClaTimes) {
            SysTeacherUser sysTeacherUser = sysTeacherUserMapper.selectSysTeacherUserByTeacherId(scClaTime.getTeacherId());
            SysUserCid sysUserCid = sysUserCidMapper.selectSysUserCidByUserId(sysTeacherUser.getUserId());
            geTuiUtils.pushToSingleByCid(sysUserCid.getCid(),"通知消息","您好，你在"+scClaTime.getClaDate()+" "+
            scClaTime.getStartTime()+"有一场点名活动");
        }



    }

}
